<template>
  <page-wrap stay-still back hide-tab title="简历预览">
    <view class="preview">
      <view class="box top-info">
        <image :src="logo" mode="aspectFill" class="logo" />
        <view class="num-time">
          <text class="text num">简历编号：{{ personInfo.personNumber_p }}</text>
          <text class="text time">更新时间：{{ personInfo.updatetime_p }}</text>
        </view>
      </view>
      <PInfo :resumeData="personInfo" :personId="pId" :status="status" />
      <view class="box contact">
        <view class="box-title">联系方式</view>
        <view class="box-item">
          <text>手机：{{ personInfo.Shouji_p }}</text>
        </view>
        <view>
          <text v-if="personInfo.Email_p">邮箱：{{ personInfo.Email_p }}</text>
        </view>
      </view>
      <AimList :allAimList="allAimList" v-if="allAimList&&allAimList.length" />
      <Exp v-if="personInfo.personWorkArr&&personInfo.personWorkArr.length" :personWorkArr="personInfo.personWorkArr" />
      <Project v-if="personInfo.work_projectArr&&personInfo.work_projectArr.length"
        :work_projectArr="personInfo.work_projectArr" />
      <Edu v-if="personInfo.personEdusArr&&personInfo.personEdusArr.length" :personEdusArr="personInfo.personEdusArr" />
      <Train v-if="personInfo.trainArr&&personInfo.trainArr.length" :trainArr="personInfo.trainArr" titleName="培训经历" />
      <Skill v-if="personInfo.otherTc_p" :otherTc_p="personInfo.otherTc_p" />
      <Cer v-if="personInfo.personCerArr&&personInfo.personCerArr.length" :personCerArr="personInfo.personCerArr" />
      <School v-if="personInfo.studentLeaderArr&&personInfo.studentLeaderArr.length"
        :studentLeaderArr="personInfo.studentLeaderArr" />
      <Award v-if="personInfo.awardArr&&personInfo.awardArr.length" :awardArr="personInfo.awardArr" />
    </view>
  </page-wrap>
</template>

<script>
import Exp from "../components/Exp.vue";
import Project from "../components/Project.vue";
import Edu from "../components/Edu.vue";
import Train from "../components/Train";
import Cer from "../components/Cer.vue";
import Skill from "../components/Skill.vue";
import PInfo from "../components/PInfo.vue";
import AimList from "../components/AimList.vue";
import School from "../components/school.vue";
import Award from "../components/award.vue";

import { getResumeData, getMyIntendedTradeList } from "@/api/index";
import ShareMixin from "@/mixins/share";

export default {
  mixins: [ShareMixin],
  components: {
    Exp,
    Project,
    Edu,
    Train,
    Cer,
    Skill,
    PInfo,
    AimList,
    School,
    Award,
  },
  data() {
    return {
      logo:
        this.$imgBaseSelf +
        "company/resume_logo.png?v=" +
        getApp().globalData.nowDate,
      personInfo: {},
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      allAimList: [],
      status: "",
    };
  },
  mounted() {
    this.getResumeInfo();
    this.getMyIntendedTradeList();
  },
  onLoad(options) {
    if (options.pId) {
      this.pId = options.pId;
    } else {
      this.pId = this.personId;
    }
    this.sharePath = "/pagesSub/resume/preview/index?pId=" + this.pId;
  },
  // onShareAppMessage() {
  //   return {
  //     title: this.$selfName,
  //     path: "/pagesSub/resume/preview/index?pId=" + this.pId,
  //   };
  // },
  // onShareTimeline() {
  //   return {
  //     title: this.$selfName,
  //     path: "/pagesSub/resume/preview/index?pId=" + this.pId,
  //   };
  // },
  methods: {
    handleFormat(text) {
      return text
        ? text
            .replace(/<\/?[^>]*>/g, "")
            .replace(/[ | ]*\n/g, "\n")
            .replace(/ /gi, "")
            .replace(/&\/?[^>]*;/g, "")
            .replace(/(\n)+/g, "\n")
        : "";
    },
    getResumeInfo() {
      uni.showLoading({
        title: "正在加载",
        mask: true,
      });
      let param = {
        personId: this.pId,
        conditionArr: JSON.stringify({
          is_mp: 1,
        }),
      };
      getResumeData(param).then((res) => {
        let data = JSON.parse(JSON.stringify(res.data || res));
        data.otherTc_p = this.handleFormat(data.otherTc_p);
        data.Grzz_p = this.handleFormat(data.Grzz_p);
        for (let key in data.personWorkArr) {
          data.personWorkArr[key].workdesc = this.handleFormat(
            data.personWorkArr[key].workdesc || ""
          );
        }
        for (let key in data.trainArr) {
          data.trainArr[key].train_desc = this.handleFormat(
            data.trainArr[key].train_desc || ""
          );
        }
        this.personInfo = data;
        uni.hideLoading();
      });
    },
    getMyIntendedTradeList() {
      let params = {
        personId: this.pId,
      };
      getMyIntendedTradeList(params).then((res) => {
        if (res.code == 200) {
          this.allAimList = res.data.myTended || [];
          this.status = +res.data.personInfo.person_status;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
$img-base-resume: $img-base + "resume/";
.preview {
  padding: 32rpx;
  .box {
    margin-bottom: $uni-spacing-col-big;
    padding: $uni-spacing-col-big;
    background-color: $uni-bg-color;
    border-radius: $uni-border-radius-lg;
    &-title {
      margin-bottom: $uni-spacing-col-lg;
      font-size: $uni-font-size-lg;
      font-weight: bold;
      color: #333333;
    }
    .icon {
      width: 36rpx;
      height: 36rpx;
      vertical-align: bottom;
    }
  }
  .top-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0;
    background-color: transparent;
    .num-time {
      font-size: $uni-font-size-sm;
      color: $uni-text-color-999;
      .text {
        display: block;
        line-height: 40rpx;
      }
    }

    .logo {
      width: 110rpx;
      height: 80rpx;
    }
  }
  .contact {
    font-size: $uni-font-size-sm;
    .box-item {
      margin-bottom: 10rpx;
    }
  }
}
</style>
